package com.seata.demo.controller;

import java.math.BigDecimal;

import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.seata.demo.service.AccountService;
import com.seata.demo.common.res.Resp;
import lombok.extern.slf4j.Slf4j;

/**
* @comments
* @author  zg
* @date 2021年2月9日
*/
@AllArgsConstructor
@Slf4j
@Validated
@RestController
@RequestMapping("/account/rest-service/")
public class AccountRestController {

    private AccountService accountService;

    /**
     * 扣钱
     * @param userId
     * @param deductMoney
     * @param tx_xid
     * @return
     */
    @PostMapping("deduct-balance")
    Resp<?> deductBalance(String userId, BigDecimal deductMoney, @RequestHeader(required = false) String tx_xid) {
        log.info("扣钱[{}]：userId={}, deductMoney={}", tx_xid, userId, deductMoney);
       /*Resp<?> resp = null;
       try {
           resp =  accountService.deductBalance(userId, deductMoney);
        } catch (Exception e) {
            resp = Resp.error(e.getMessage());
            log.error("", e);
        }
       return resp;*/
        return accountService.deductBalance(userId, deductMoney);
    }
    
}
